<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模拟super</title>
</head>
<body>
<script>

   
    function User(name) {
        this.name = name
    }

    User.prototype.get1 = function () {
        console.log(1)
    }

    function Student(name, age) {
        //类似于class中的super() 如果写成原型继承的话调用父类的构造函数使用call进行调用
        /*
        * 因为子类在访问父类的时候是子类在访问所以要确保this是子类 而且如果这里直接调用User()的话
        * this是window
        *
        * */
        User.call(this, name)
        this.age = age
    }

    Student.prototype = new User()
    Student.prototype.constructor = Student

    Student.prototype.get2 = function () {
        console.log(2)
    }

    Student.prototype.get3 = function () {
        User.prototype.get1.call(this)
    }

    let stu = new Student('A', 12)
    stu.get1()
    stu.get2()
    stu.get3()


    class User1 {
        constructor(name) {
            this.name = name
        }

        get1() {
            console.log(1)
        }
    }

    class Student1 extends User1 {
        constructor(name, age) {
            super(name);
            this.age = age
        }

        get2() {
            super.get1();
            console.log("get2")
        }
    }

    let stu1 = new Student1('L', 100)
    stu1.get1()
    stu1.get2()


</script>
</body>
</html>